package zy1208.zy8;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;

public class demo {
    public static void main(String[] args) throws Exception {
        List<String> lines = FileUtils.readLines(new File("src/zy1208/zy8/CatData.txt"));
        ArrayList<Cat> clist = new ArrayList<>();
        for (String line : lines) {
            String re = line.replace(" ", "=");
            String[] split = re.split("=");
            Class<?> aClass = Class.forName(split[0]);
            Constructor<?> c = aClass.getDeclaredConstructor(String.class, int.class);
            int a=0;
            a=Integer.parseInt(split[4]);
            Object o = c.newInstance(split[2],a);
            clist.add((Cat) o);
        }
        for (Cat c : clist) {
            System.out.println(c.getName()+" "+c.getAge());
        }
    }
}
